/*
 * serial.c
 *
 *  Created on: Apr 2, 2012
 *      Author: Tri_D
 */

#include "serial.h"
#include "sma.h"
#include <mc9s08ll64.h>

void Ser_Init(Serial_t * pS)
{
	init_que512(&pS->Rx);
	(void) memset(pS->Tx, 0, MAX_TX_CHAR_SIZE);
	pS->Ptr = 0;
	pS->Size = 0;
	pS->Flag = TX_SER_READY;
}


void Tx_Ser(Serial_t * pS, uint8_t * pdata, uint8_t size)
{
	while(pS->Flag == TX_SER_NOT_READY);		// Wait until last transmit ready
	(void) memcpy(pS->Tx, pdata, size);
	pS->Ptr = 0;
	pS->Size = size;
	SCI1D = pS->Tx[pS->Ptr++];
	pS->Flag = TX_SER_NOT_READY;
	SCI1C2_TIE = 1;							// Turn on serial transmit interrupt
}



